Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge package:mockito #2293

Closed
wants to merge 643 commits into from
Closed

Merge package:mockito #2293

wants to merge 643 commits into from

Conversation

mosuem
Copy link
Member

@mosuem mosuem commented Oct 17, 2024

  • Move and fix workflow files, labeler.yaml, and badges in the README.md
  • Rev the version of the package, so that pub.dev points to the correct site
  • Add a line to the changelog:
* Move to `dart-lang/test` monorepo.
  • Add the package to the top-level readme of the monorepo:
| [mockito](pkgs/mockito/) | A mock framework inspired by Mockito with APIs for Fakes, Mocks, behavior verification, and stubbing. | [![pub package](https://img.shields.io/pub/v/mockito.svg)](https://pub.dev/packages/mockito) |
> [!IMPORTANT]  
> This repo has moved to https://github.com/dart-lang/test/tree/master/pkgs/mockito
  • Publish using the autopublish workflow
  • Push tags to GitHub using git tag --list 'mockito*' | xargs git push origin
  • Close open PRs in dart-lang/mockito with the following message:
Closing as the [dart-lang/mockito](https://github.com/dart-lang/mockito) repository is merged into the [dart-lang/test](https://github.com/dart-lang/test) monorepo. Please re-open this PR there!
  • Transfer issues by running dart run pkgs/repo_manage/bin/report.dart transfer-issues --source-repo dart-lang/mockito --target-repo dart-lang/test --add-label package:mockito --apply-changes
  • Archive https://github.com/dart-lang/mockito/
  • Import to g3 - see internal cl/705463525

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

lauweijie and others added 30 commits June 29, 2021 09:42
* Allow two mocks of the same class (with different type arguments) to be
  specified with different fallback generators.
* Allow fallback generators on super types of a mocked class.

This change strongly suggested a code restructuring, moving the bulk of the code-building into a new "MockClassInfo" class, extracted from MockLibraryInfo.

I've incorporated this change; most of the fields on MockLibraryInfo is moved to MockClassInfo; only a few fields remain, which are fields important to be shared across class-building code.

PiperOrigin-RevId: 378307281
dart-lang/mockito@cc1b0c8

Fix spelling and grammar typos in README.md

PiperOrigin-RevId: 382620480
dart-lang/mockito@825e213

Follow Dart file conventions | Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

PiperOrigin-RevId: 382634050
PiperOrigin-RevId: 382755039
Generated code may import 'src' files.

PiperOrigin-RevId: 382756565
The inference_failure_on_instance_creation error will trigger on code like

```
returnValueForMissingStub: Future.value()
```

because, even though no value has been given to `value()`, that does not
affect the Future's type (it still defaults to `void`). Explicitly using
`Future<void>.value()` satisfies the check.

PiperOrigin-RevId: 382770034
Without this support, mockito tried to create a FakeFunction which implemented Function, which is not allowed.

Fixes dart-lang/mockito#442

PiperOrigin-RevId: 384852004
…e<T>`.

Before this fix, we would only return `[]` which had an implicit dynamic: `<dynamic>[]`. The proper return value should explicitly include the expected type argument.

Existing test cases cover the desired behavior.

Also replace `var` with `final` in surrounding code.

Fixes dart-lang/mockito#445

PiperOrigin-RevId: 384965296
PiperOrigin-RevId: 385356711
If the generated code needs to represent a type, `T`, and that type is declared
in library `L`, then we now prefer to import a library which _exports_ `L` (if
one exists), over importing `L` directly.

To find such a library, we look at the type, `U` which references `T`. Perhaps
`U` is a class to mocked, and `U` has a method with a return type `T`, or `U` is
a supertype of a class to be mocked, which has a method with a parameter type
`T`, etc. We examine all of the import libraries, `IL`, of the library in which
`U` is declared, and all of the libraries which are exported by the libraries
`IL`.

If the type `T` is declared in a library which is exported as a conditional
export, this strategy avoids complications with the conditional export.
Additionally, as a heuristic, it generally leads to public libraries which
export private implementation, avoiding importing the private implementation
directly.

Fixes dart-lang/mockito#443

PiperOrigin-RevId: 385425794
PiperOrigin-RevId: 385440655
We might generate setters without getters.

PiperOrigin-RevId: 385802287
* Properly reference types in overridden `toString` implementations.
  Fixes dart-lang/mockito#438
* Override `toString` in a Fake implementation when the class-to-be-faked has
  a superclass which overrides `toString` with additional parameters.
  Fixes dart-lang/mockito#371

PiperOrigin-RevId: 385852381
…rarchy.

Previously, mixins were being applied in the wrong order. By using analyzer's InheritanceManager3, instead of my homespun inheritance-walking algorithm, we
solve this problem, and perhaps other unreported issues.

Fixes dart-lang/mockito#456

PiperOrigin-RevId: 387741287
Without this fix, the generator could generate multiple classes with the same name.

Fixes dart-lang/mockito#441

PiperOrigin-RevId: 388959500
* comment fix, long string fix
* bump version and add to CHANGELOG

PiperOrigin-RevId: 390005036
PiperOrigin-RevId: 392063226
This prepares for landing https://dart-review.googlesource.com/c/sdk/+/190360 into the analyzer.

PiperOrigin-RevId: 394480352
We would like to remove them.
Use `DartType.alias` instead.

PiperOrigin-RevId: 395945062
typo fix

PiperOrigin-RevId: 395962959
Update README.md.

Tweak new text.

PiperOrigin-RevId: 395963615
Add ignore_for_file: camel_case_types to generated file

PiperOrigin-RevId: 395993046
@mosuem
Copy link
Member Author

mosuem commented Oct 29, 2024

I don't see the pubspec, but I imagine the deps just need to be bumped. Or mockito in google3 might be using unpublished elements from analyzer.

It seems like stable Dart does not yet support some features. I would advise to move this package with the failing CI, and fix the issue in a follow up. IIUC, fixing would require depending on a dev version of Dart, or removing the use of these features.

@mosuem mosuem force-pushed the merge-mockito-package branch from 4dd33dd to 7c4bf82 Compare October 29, 2024 16:08
…o formatting, so I just loosened the tests a bit manually.

In auto_mocks_test, there were about 50 failures, so I cobbled together a more generic approach. I used the existing _containsAllOf() function to hook in a custom matcher that ignores differences in whitespace and trailing commas.

PiperOrigin-RevId: 691644163
…t to try to not be sensitive to formatting changes before I realized that wouldn't work in auto_mocks_test and came up with something more robust.

It turns out the simpler approach is still too brittle and some tests fail under the new style (specifically, the new formatter splits after `=>` when the old one doesn't). So I hoisted containsIgnoringFormatting() into a separate library and refactored custom_mocks_test to use it too.

PiperOrigin-RevId: 691836139
srawlins and others added 13 commits November 13, 2024 09:10
We generally preserve positional parameter names, but in the case of wildcard
parameters, we must rename them. We cannot override a wildcard parameter with a
wildcard parameter, since we do use the parameter (we pass it to
`super.noSuchMethod` in a call to `Invocation.method`). This change introduces
some renaming logic for wildcard parameters, using new method-unique parameter
names.

PiperOrigin-RevId: 696158750
Bumps the github-actions group with 2 updates in the / directory: [actions/checkout](https://github.com/actions/checkout) and [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart).


Updates `actions/checkout` from 4.1.7 to 4.2.2
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@692973e...11bd719)

Updates `dart-lang/setup-dart` from 1.6.5 to 1.7.0
- [Release notes](https://github.com/dart-lang/setup-dart/releases)
- [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md)
- [Commits](dart-lang/setup-dart@0a8a0fc...e630b99)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
- dependency-name: dart-lang/setup-dart
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <[email protected]>
…uplicate typedefs

dart-lang/mockito#776

Closes: dart-lang/mockito#775
Closes: dart-lang/mockito#777
Closes: dart-lang/mockito#778

The fix for these issues is closely related so I've done both of them in a single PR.

- Mockito wasn't checking for typedefs/aliases in `typeArguments`
- it also wasn't looking into records on type args.
- Typedefs which had the same underlying type were ignored even if the typedef had a different name

These issues cause the dreaded `is missing from the asset URI mapping` error.

See the related issue for a repro of each of these.

I've also added regression tests for all of these.

PiperOrigin-RevId: 702712435
Also bump some dep constraints:

* analyzer ^6.9.0 is required as mockito uses some APIs that were introduced in
  that version.
* That version of analyzer requires a Dart 3.6.0 SDK, so bump that constraint.
* build_runner ^6.11.0 is required to avoid an issue looking for the wrong
  frontend_server snapshot.

PiperOrigin-RevId: 702747878
@mosuem mosuem force-pushed the merge-mockito-package branch from 7c4bf82 to 7c7cbf5 Compare December 12, 2024 12:44
Copy link

Package publishing

Package Version Status Publish tag (post-merge)
package:mockito 5.4.5-dev.0 ready to publish mockito-v5.4.5-dev.0
package:checks 0.3.1-wip WIP (no publish necessary)
package:fake_async 1.3.2 already published at pub.dev
package:matcher 0.12.18-wip WIP (no publish necessary)
package:test 1.25.12 already published at pub.dev
package:test_api 0.7.4 already published at pub.dev
package:test_core 0.6.8 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@jakemac53
Copy link
Contributor

I looked a bit at the issue tracker for this package and I am pretty concerned about merging it into the test repo.

This package is active enough I think it should stay in its own repo. I am not able or willing to take ownership of it and don't want to be on the hook for fielding the issues, but would feel obligated to if it was in this repo.

@mosuem
Copy link
Member Author

mosuem commented Dec 17, 2024

Hm. In my personal opinion, merging mockito into this repo should really not imply that you are in any way an owner, but I can definitely see why it would feel that way.

@devoncarew @srawlins any ideas?

@srawlins
Copy link
Member

I don't have any feelings about where it lives. I have not been a good owner, but I won't ask anyone else to.

@devoncarew
Copy link
Member

mockito is pretty up in the air currently (should we own it? do we have the time to maintain and move it forward?). Let's hold off on moving this to a monorepo until we have more clarity on the medium term / long term plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.